//using System;
//using TextCompiler.Expressions;

//namespace TextCompiler.Expressions.Terminals.Parsing
//{
//    public class ParseFilterSymbolTerminal : Symbol
//    {
//        public int? MinimumCharacters { get; private set; }
//        public int? MaximumCharacters { get; private set;  }
//        public Func<char, bool> FirstCharacterPredicate { get; private set; }
//        public Func<char, bool> OtherCharactersPredicate { get; private set; }

//        public ParseFilterSymbolTerminal(Func<char, bool> firstCharacter, Func<char, bool> otherCharacters, int? minimum, int? maximum)
//        {
//            FirstCharacterPredicate = firstCharacter;
//            OtherCharactersPredicate = otherCharacters;
//            MinimumCharacters = minimum;
//            MaximumCharacters = maximum;
//            TypeOperation = OperationType.Parsing;
//        }

//        public override ParsingResult<string> Parse(GrammarContext context, int index)
//        {
//            string text = context.Text;
//            int position = index;
//            int maxPosition = text.Length;
//            if (MaximumCharacters.HasValue && MaximumCharacters.Value < maxPosition - index)
//                maxPosition = MaximumCharacters.Value + index;

//            if (position < maxPosition && FirstCharacterPredicate(text[position]))
//            {
//                position++;

//                while (position < maxPosition && OtherCharactersPredicate(text[position]))
//                    position++;
//            }

//            int length = position - index;

//            if (!MinimumCharacters.HasValue || length >= MinimumCharacters.Value)
//                return new ParsingResult<string>(index, length, text.Substring(index, length));
//            return null;
//        }

//        public override void ParseNode(GrammarContext context, ParsingNodeResult node)
//        {
//            string text = context.Text;
//            int position = node.Index;
//            int maxPosition = text.Length;
//            if (MaximumCharacters.HasValue && MaximumCharacters.Value < maxPosition - node.Index)
//                maxPosition = MaximumCharacters.Value + node.Index;

//            if (position < maxPosition && FirstCharacterPredicate(text[position]))
//            {
//                position++;

//                while (position < maxPosition && OtherCharactersPredicate(text[position]))
//                    position++;
//            }

//            int length = position - node.Index;

//            if (!MinimumCharacters.HasValue || length >= MinimumCharacters.Value)
//            {
//                node.Length = length;
//                node.Value = text.Substring(node.Index, length);
//            }

//            if (maxPosition != position)
//                length++;

//            node.ExploredLength = length;
//        }
//    }
//}